import {TInitFlag} from "@/common/common";
import {makeAutoObservable, runInAction} from "mobx";
import _ from "lodash";
import {apiQueryCameraInfosByRadar} from "@/common/apis/cameraInfo";

class CameraInfoStore {
  constructor() {
    makeAutoObservable(this)
  }

  initialFlg: TInitFlag = "initial";
  cameraInfos: any[] = [];

  async queryCameraInfos() {
    if (!_.isEmpty(this.cameraInfos)) {
      return this.cameraInfos;
    }
    if (this.initialFlg !== "initial") {
      return;
    }
    this.initialFlg = "initialing";
    const res = await apiQueryCameraInfosByRadar({});
    runInAction(() => {
      if (res.code === 0) {
        this.cameraInfos = res.data || []
      }
      this.initialFlg = "initialled";
    })
  }
}

export default new CameraInfoStore()
